<?php
/**
 * User: jintao
 * 售后单请求相关接口
 */
class erpapi_shop_request_aftersale extends erpapi_shop_request_abstract
{
    public function addAfterSale($returninfo){}

    protected function __afterSaleApi($status) {
        return '';
    }

    protected function __formatAfterSaleParams($aftersale,$status) {
        return array();
    }

    public function updateAfterSaleStatus($aftersale,$status='' , $mod='async'){
        $rs = array();
        if(empty($aftersale)) {
            return array('rsp'=>'fail', 'msg'=>'no return');
        }
        $orderModel = app::get('ome')->model('orders');
        $order      = $orderModel->dump($aftersale['order_id'], 'order_bn');
        if (!$status) {
            $status = $aftersale['status'];
        }
        $api_method = $this->__AfterSaleApi($status);
        if (empty($api_method)) {
            return true;
        }
        $title = '店铺('.$this->__channelObj->channel['name'].')更新[交易售后状态]:'.$status.',(订单号:'.$order['order_bn'].'退款单号:'.$aftersale['return_bn'].')';
        $params = $this->__formatAfterSaleParams($aftersale,$status);
        $params['tid'] = $order['order_bn'];
        if($params['status']=='5'){
            $params['content']!='' ? $params['content'] : 'erp拒绝';
        }
        $callback = array();
        if ($mod == 'async') {
            $callback = array(
                'class' => get_class($this),
                'method' => 'callback',
            );
        }
        $result = $this->__caller->call($api_method, $params, $callback, $title, 10, $order['order_bn']);
        if(isset($result['msg']) && $result['msg']){
            $rs['msg'] = $result['msg'];
        }elseif(isset($result['err_msg']) && $result['err_msg']){
            $rs['msg'] = $result['err_msg'];
        }elseif(isset($result['res']) && $result['res']){
            $rs['msg'] = $result['res'];
        }
        $rs['rsp'] = $result['rsp'];
        $rs['data'] = $result['data'] ? json_decode($result['data'], true) : array();
        return $rs;
    }

    public function addReship($reship){}

    public function updateReshipStatus($reship){}

}